<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <button class="start">开始</button>
    <button class="stop">结束</button>
    我真帅+ <span>0</span>
  </body>
  <script>
    window.onload = function () {
      const span = document.querySelector("span");
      let timeId = null;
      let flag = false;
      document.querySelector(".start").onclick = function () {
        if (flag) return;
        flag = true;
        timeId = setInterval(function () {
          span.innerText++;
        }, 300);
      };

      document.querySelector(".stop").onclick = function () {
        flag = false;
        clearInterval(timeId);
      };
    };
  </script>
</html>
